package com.example.javaow.controller;

import com.example.javaow.domain.base.ResponseResult;
import com.example.javaow.domain.dto.Login;
import com.example.javaow.domain.dto.RegisterDTO;
import com.example.javaow.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 登录接口
     * @param login 登录信息
     * @return 带 token 的响应结果
     */
    @PostMapping("/login")
    public ResponseResult<Map<String, Object>> login(@RequestBody Login login) {
        return userService.login(login);
    }


    @PostMapping("/register")
    public ResponseResult<String> register(@RequestBody RegisterDTO registerDTO) {
        return userService.register(registerDTO);
    }
}